#include<bits/stdc++.h>
using namespace std;
int n,a[107],maxn=-1;
void f(int d,int g,int r,int b){
    if(d>n){
        maxn=max(maxn,g);return;
    }
    f(d+1,g+(a[d]==r?a[d]:0),a[d],b);
    f(d+1,g+(a[d]==b?a[d]:0),r,a[d]);
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;cin>>T;
    while(T--){
        maxn=-1;
        cin>>n;
        for(int i=1;i<=n;++i)cin>>a[i];
        f(1,0,-1,-1);
        cout<<maxn<<'\n';
    }
    return 0;
}
